﻿package mortal.game.view.tianDiRank.item
{
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import frEngine.pools.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.view.common.*;
    import mortal.game.view.tianDiRank.data.*;
    import mortal.mvc.core.*;

    public class TianDiPlayerSp extends GSprite
    {
        private var _effectPlayer:EffectPlayer;
        private var _roleModelPlayer:UserModelPlayer;
        private var _rect3d:Rect3DObject;
        private var _toolTipSpr:ToolTipSprite;
        private var _toolBg:GBitmap;
        protected var _nameBg:ScaleBitmap;
        protected var _noNum:GBitmap;
        protected var _nameTxt:GTextFiled;
        protected var _challengeBtn:GLoadedButton;
        private var _info:Object;
        private var _pos:int;

        public function TianDiPlayerSp()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._nameBg = UIFactory.bg(-39, -70, 145, 25, this, ImagesConst.PetNameBg);
            this._noNum = UIFactory.gBitmap(ImagesConst.TianDiRankPosNum1, 0, 0, this);
            this._nameTxt = UIFactory.gTextField("", 479, 126, 150, 25, this, GlobalStyle.textFormatLv.setSize(13));
            var _loc_1:Boolean = false;
            this._nameTxt.mouseEnabled = false;
            this._nameTxt.selectable = _loc_1;
            this._challengeBtn = UIFactory.gLoadedButton(ImagesConst.TianDiRankChallengBtn_upSkin, -6, 50, 70, 25, this);
            this._challengeBtn.label = "";
            this._toolTipSpr = UICompomentPool.getUICompoment(ToolTipSprite);
            this._toolTipSpr.mouseEnabled = true;
            this._toolTipSpr.mouseChildren = false;
            this._toolTipSpr.x = -60;
            this._toolTipSpr.y = -20;
            this.addChild(this._toolTipSpr);
            this._toolBg = GlobalClass.getBitmap(BitmapDataConst.AlphaBMD);
            this._toolBg.width = 160;
            this._toolBg.height = 70;
            this._toolTipSpr.addChild(this._toolBg);
            this._toolTipSpr.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._toolTipSpr.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            this._challengeBtn.configEventListener(MouseEvent.CLICK, this.onShowEnter);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this._roleModelPlayer)
            {
                this._rect3d.disposeObj3d(this._roleModelPlayer);
                this._roleModelPlayer = null;
            }
            if (this._effectPlayer)
            {
                this._rect3d.disposeObj3d(this._effectPlayer);
                this._effectPlayer = null;
            }
            this._rect3d = null;
            this._toolTipSpr.dispose(param1);
            this._toolTipSpr = null;
            this._challengeBtn = null;
            if (this._noNum)
            {
                this._noNum.dispose(param1);
                this._noNum = null;
            }
            this._nameBg.dispose(param1);
            this._nameBg = null;
            this._nameTxt.dispose(param1);
            this._nameTxt = null;
            return;
        }// end function

        public function initModule(param1:Rect3DObject) : void
        {
            this._rect3d = param1;
            if (this._rect3d && this._roleModelPlayer)
            {
                this._rect3d.disposeObj3d(this._roleModelPlayer);
            }
            this._roleModelPlayer = FrObjectPool.getObject(UserModelPlayer, this);
            return;
        }// end function

        private function onShowEnter(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.TianDiRankCkToShowPanel, {info:this._info, pos:this._pos}));
            return;
        }// end function

        public function updatePlayerInfo(param1:Object, param2:int, param3:int, param4:int) : void
        {
            this._info = param1;
            this._pos = param2;
            if (param1.isEmpty)
            {
                this.updateDefaultBody(null, this._pos, param3, param4);
            }
            else
            {
                this.updateBody(this._info, this._pos, param3, param4);
            }
            this.updateTitle(this._info, this._pos, param3, param4);
            this.updatePosNumAndName(this._info, this._pos);
            this.setToolTip(this._info, this._pos);
            return;
        }// end function

        private function updateBody(param1:Object, param2:int, param3:int, param4:int) : void
        {
            var _loc_5:* = param1.career;
            var _loc_6:* = param1.sex;
            var _loc_7:* = param1.clothes;
            var _loc_8:* = param1.weapon;
            var _loc_9:* = param1.hair;
            var _loc_10:* = param1.wing;
            this._roleModelPlayer.updateInfo(_loc_5, _loc_6, _loc_7, _loc_8, _loc_9, _loc_10);
            this._roleModelPlayer.scaleAll = 1.5;
            this._roleModelPlayer.useLight();
            this._roleModelPlayer.rotationX = 0;
            this._roleModelPlayer.rotationY = 0;
            this._roleModelPlayer.bodyPlayer.selectEnabled = true;
            this._rect3d.addObject3d(this._roleModelPlayer, param3, param4);
            return;
        }// end function

        private function updateDefaultBody(param1:Object, param2:int, param3:int, param4:int) : void
        {
            var _loc_5:int = 1;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:int = 110000;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            this._roleModelPlayer.updateInfo(_loc_5, _loc_6, _loc_7, _loc_8, _loc_9, _loc_10);
            this._roleModelPlayer.scaleAll = 1.5;
            this._roleModelPlayer.useLight();
            this._roleModelPlayer.rotationX = 0;
            this._roleModelPlayer.rotationY = 0;
            this._roleModelPlayer.bodyPlayer.selectEnabled = true;
            this._rect3d.addObject3d(this._roleModelPlayer, param3, param4);
            return;
        }// end function

        public function updateMonsterBody(param1:Object, param2:int, param3:int, param4:int) : void
        {
            var _loc_5:* = TianDiRankUtil.getIndex();
            var _loc_6:* = TianDiRankUtil.getMonsterCodeByPos(_loc_5, param2, 1);
            var _loc_7:* = BossConfig.instance.getInfoByCode(_loc_6);
            if (this._roleModelPlayer == null)
            {
                return;
            }
            this._roleModelPlayer.updateInfo(0, 1, 0, 0, 0, 0);
            this._roleModelPlayer.bodyPlayer.changeAction(ActionName.Stand);
            this._roleModelPlayer.bodyPlayer.hangBoneName = BoneConst.MountHangModelBone;
            this._roleModelPlayer.bodyPlayer.selectEnabled = false;
            this._roleModelPlayer.bodyPlayer.play();
            this._roleModelPlayer.bodyPlayer.setRotation(0, 0, 0);
            this._roleModelPlayer.bodyPlayer.load(_loc_7.mesh + ".md5mesh", _loc_7.bone + ".skeleton", _loc_7.texture);
            this._rect3d.addObject3d(this._roleModelPlayer, param3, param4 - 30);
            return;
        }// end function

        private function updateTitle(param1:Object, param2:int, param3:int, param4:int) : void
        {
            var _loc_5:* = param1.icon;
            if (this._effectPlayer)
            {
                this._rect3d.disposeObj3d(this._effectPlayer);
                this._effectPlayer = null;
            }
            this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(_loc_5, null, this._rect3d.renderList, false);
            this._effectPlayer.play();
            this._rect3d.addObject3d(this._effectPlayer, param3, param4 - 238);
            return;
        }// end function

        private function updatePosNumAndName(param1:Object, param2:int) : void
        {
            var _loc_3:* = param2;
            var _loc_4:* = param1.nameStr;
            var _loc_5:* = this.getNoNumHei(_loc_3);
            this._nameBg.x = this._challengeBtn.x - 33;
            this._nameBg.y = this._challengeBtn.y - _loc_5 - 25;
            if (this._noNum)
            {
                this._noNum.dispose();
            }
            this._noNum = UIFactory.gBitmap(ImagesConst["TianDiRankPosNum" + TianDiRankUtil.getPosNum(_loc_3)], this._nameBg.x + 27, this._nameBg.y + 6, this);
            this._nameTxt.x = this._noNum.x + 41;
            this._nameTxt.y = this._nameBg.y + 1;
            if (_loc_4 == null || _loc_4 == "")
            {
                this._nameTxt.text = "" + Language.getString(71940);
                this._nameTxt.textColor = 16711680;
            }
            else
            {
                this._nameTxt.text = "" + _loc_4;
                this._nameTxt.textColor = 65280;
            }
            return;
        }// end function

        private function setToolTip(param1:Object, param2:int) : void
        {
            var _loc_10:Object = null;
            var _loc_3:* = TianDiRankUtil.getIndex();
            var _loc_4:* = TianDiRankUtil.getPosAttByPos(_loc_3, this._pos);
            var _loc_5:String = "";
            var _loc_6:int = 0;
            while (_loc_6 < _loc_4.length)
            {
                
                _loc_10 = _loc_4[_loc_6];
                _loc_5 = _loc_5 + _loc_10["attrName"];
                _loc_5 = _loc_5 + (":+" + _loc_10["attrValue"]);
                _loc_5 = _loc_5 + "\n";
                _loc_6++;
            }
            var _loc_7:* = TianDiRankConfig.instance.copyArr[_loc_3][this._pos];
            var _loc_8:* = _loc_7.titleId;
            var _loc_9:* = TianDiRankUtil.getTitleCombat(_loc_8);
            _loc_5 = _loc_5 + (Language.getString(71944) + _loc_9);
            this._toolTipSpr.toolTipData = _loc_5;
            return;
        }// end function

        private function getNoNumHei(param1:int) : int
        {
            return 41;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

    }
}
